
from pyecharts.charts import Bar, Timeline
from pyecharts.options import *
from pyecharts.globals import ThemeType

bar1 = Bar()
bar1.add_xaxis(["中国", "美国", "英国"])
bar1.add_yaxis("GDP", [30, 20, 10], label_opts= LabelOpts(position= "right"))
bar1.reversal_axis()# 反转x y轴

bar2 = Bar()
bar2.add_xaxis(["中国", "美国", "英国"])
bar2.add_yaxis("GDP", [40, 25, 15], label_opts= LabelOpts(position= "right"))
bar2.reversal_axis()# 反转x y轴

bar3 = Bar()
bar3.add_xaxis(["中国", "美国", "英国"])
bar3.add_yaxis("GDP", [70, 60, 20], label_opts= LabelOpts(position= "right"))
bar3.reversal_axis()# 反转x y轴

# 构建时间线对象
timeline = Timeline(
    {"theme": ThemeType.LIGHT}
)

# 在时间线内添加柱状图对象
timeline.add(bar1, "点1")
timeline.add(bar2, "点2")
timeline.add(bar3, "点3")

# 设置
timeline.add_schema(
    is_auto_play= True, # 自动播放
    play_interval=1000, # 自动播放时间间隔，单位ms
    is_timeline_show= True,
    is_loop_play= True
)

timeline.render("时间线柱状图.html")